package qlsl.androiddesign.popupwindow.subwindow;

import java.util.ArrayList;
import java.util.List;

import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.adapter.subadapter.ServerTypeAdapter;
import qlsl.androiddesign.popupwindow.basewindow.PopupWindow;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;

import com.qlsl.androiddesign.kuaiwa.R;

/**
 * 服务类型PopupWindow<br/>
 */
@SuppressLint("ViewConstructor")
public class ServeTypePopupWindow extends PopupWindow {

	private ListView listView;

	public ServeTypePopupWindow(BaseActivity activity) {
		super(activity);
		initView();
		setPopupWindowAttribute();
		initData();
	}

	@SuppressLint("InflateParams")
	private void initView() {
		LayoutInflater inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rootView = inflater.inflate(R.layout.window_serve_type, null);
		setContentView(rootView);
		listView = (ListView) rootView.findViewById(R.id.listView);
	}

	private void setPopupWindowAttribute() {
		setWidth(LayoutParams.MATCH_PARENT);
		setHeight(LayoutParams.WRAP_CONTENT);
		setFocusable(true);
		setAnimationStyle(R.style.AnimTop);
		ColorDrawable colorDrawable = new ColorDrawable(activity.getResources()
				.getColor(R.color.bg_common_content_view));
		setBackgroundDrawable(colorDrawable);
		setOutsideTouchable(true);
	}

	private void initData() {
		setGridViewData();
	}

	private void setGridViewData() {
		String[] provinces = new String[] { "不限", "整车大修", "日常保养", "液压系统",
				"机械动力", "底盘", "电路", "钣金喷漆", "发动机", "破碎锤", "滤芯", "油品", "易损件",
				"磨耗件", "发动机配件", "液压配件", "底盘配件" };
		List<String> list = new ArrayList<String>();
		for (String text : provinces) {
			list.add(text);
		}
		ServerTypeAdapter adapter = new ServerTypeAdapter(activity, list);
		listView.setAdapter(adapter);
	}

	public String getSelectItem(View view) {
		int position = listView.getPositionForView(view);
		ServerTypeAdapter adapter = (ServerTypeAdapter) listView.getAdapter();
		return adapter.getItem(position);
	}
}
